function[] = gsfc_psd2(first, last, dataset)
global Project;

%  PSD using pwelsh function - ask result frequency resolution
%  Ask for Result Resolution
% prompt = {'Frequency Resolution(Hz):', 'Lower Freq(Hz):', 'Upper Freq(Hz):'};
% dlgTitle = 'PSD Analysis Settings';
% lineNo = [1 30; 1 20; 1 20];
% defAns = {'2', '20', '2000'};
% settings = inputdlg(prompt, dlgTitle, lineNo, defAns);
% freq_res = str2num(settings{1,1});
% LFreq = str2num(settings{2,1});
% UFreq = str2num(settings{3,1});

SampleRate = Project.Test_Item.Run.Sample_Rate;
[freq_res, LFreq, UFreq] = Frequency_Parameters;

% Determine closest block size 2^n - to use FFT
n = ceil(log(SampleRate/freq_res)/log(2));
window = 2^n;
noverlap = (2^n)/2;
nfft = 2^n;
w = waitbar(0,'Please wait...');

for i = 1:Project.Test_Item.Run.Num_Chan
    x = Project.Test_Item.Run.Channel(i).Time_His(first:last);
    [Pxx, f] = pwelch(x, window, noverlap, nfft, SampleRate);
    % Added 22-Feb-2005 by Chris McLeod
    if i == 1
        LFreqIndex = floor(LFreq / f(2)) + 1;
        UFreqIndex = floor(UFreq / f(2));
    end
    Project.Test_Item.Run.Channel(i).Analysis(dataset).Type = 2;
    Project.Test_Item.Run.Channel(i).Analysis(dataset).Abs = f(LFreqIndex:UFreqIndex)';
    Project.Test_Item.Run.Channel(i).Analysis(dataset).Ord = Pxx(LFreqIndex:UFreqIndex)';
    Project.Test_Item.Run.Channel(i).Analysis(dataset).FPoint = first;
    Project.Test_Item.Run.Channel(i).Analysis(dataset).LPoint = last;
    waitbar(i/Project.Test_Item.Run.Num_Chan);
end
close(w);
